<?php
/*
 * @Description    : 
 * @Version        : 1.0.0
 * @Author         : QianLong
 * @Date           : 2021-03-29 23:35:46
 * @LastEditors    : QianLong
 * @LastEditTime   : 2024-04-25 17:26:21
 */

namespace app\download\controller;

use app\BaseController;
use think\facade\View;
use think\facade\Db;

class Index extends BaseController
{
	public function app($id = '')
	{
		$infoData = Db::connect('mongodb')->name('app_list')->field('_id,title,bg_pic,icon,bg_type,btn_color,scheme,uid')->where('_id', $id)->find();
		if (empty($infoData)) {
			echo '内容无效';
			exit;
		}
		if ($infoData['bg_type'] == 0) {
			$infoData['bg_pic'] = '';
		}
		$versionData = Db::connect('mongodb')->name('app_version_'. $infoData['uid'])->field('platform,url_android,store_url_android,url_ios,upgrade_title')->where('app_id', $id)->where('status', 1)->where('version_type', 'zhengshi')->where('upgrade_type','all')->find();
		if (!empty($versionData)) {
			$versionData['url_android'] = (isset($versionData['store_url_android']) && !empty($versionData['store_url_android']) && strlen($versionData['store_url_android']) > 5) ? $versionData['store_url_android'] : $versionData['url_android'];
		}
		unset($infoData['uid']);
		if (!empty($versionData)) {
			$result = array_merge($infoData, $versionData);
		}else{
			$result = $infoData;
			$result['url_android'] = '';
			$result['url_ios'] = '';
		}
		View::assign([
			'result'  => $result
		]);
		return View::fetch();
	}
}
